package siam.ui;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.border.BevelBorder;

import siam.core.ExtractFiles;
import siam.core.MasterOfGame;
/**
 * Class which represent the main frame of Siam game
 * @author Motassim Saad
 *
 */
public class SiamFrame extends JFrame {
	
	private Joueur j1 = new Joueur( JOptionPane.showInputDialog(null, "Nom joueur 1 : ", 
			"Tapez nom joueur 1", 1));
	private Joueur j2 = new Joueur(JOptionPane.showInputDialog(null, "Nom joueur 2 : ", 
			"Tapez nom joueur 2", 1));
	MasterOfGame masterGame= MasterOfGame.instance;
	private InactivePiecesPanel inactivePiecePanelJ2;
	private InactivePiecesPanel inactivePiecePanelJ1;
	private JMenuBar menuBar=new JMenuBar();;
	private JMenuItem menu=new JMenuItem("Nouvelle partie");
	private SiamPanel siamPanel;;
	private MouseListener mouseListener =new MouseListener() {
		
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		public void mouseClicked(MouseEvent e) {
			masterGame.newGame();
			
		}
	};
	
	/**
	 * Create the panel
	 */
	public SiamFrame() {
	
		ExtractFiles.init();ExtractFiles.getInstance().extractFiles();
		init();
		
		EventControler.instance.setPane(siamPanel);
		EventControler.instance.setFrame(this);
		
		
		masterGame.init(siamPanel, j1 , j2);
		masterGame.setFrame(this);
	
		
		menuBar.add(menu);
		this.setJMenuBar(menuBar);
		
		menu.addMouseListener(mouseListener);
	}
	
	private void init() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
		
		inactivePiecePanelJ1 = new InactivePiecesPanel(j1);
		inactivePiecePanelJ1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		inactivePiecePanelJ1.setBackground(Color.DARK_GRAY);
		getContentPane().add(inactivePiecePanelJ1);
		inactivePiecePanelJ1.setLayout(new FlowLayout(FlowLayout.CENTER, 45, 5));
		
		siamPanel = new SiamPanel();
		siamPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		getContentPane().add(siamPanel);
		
		 inactivePiecePanelJ2 = new InactivePiecesPanel(j2);
		inactivePiecePanelJ2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		inactivePiecePanelJ2.setBackground(Color.DARK_GRAY);
		
		getContentPane().add(inactivePiecePanelJ2);
		inactivePiecePanelJ2.setLayout(new FlowLayout(FlowLayout.TRAILING, 45, 5));
		
	}

	public InactivePiecesPanel getInactivePiecePanelJ1() {
		return inactivePiecePanelJ1;
	}
	public InactivePiecesPanel getInactivePiecePanelJ2() {
		return inactivePiecePanelJ2;
	}

	public void initAll() {
		init();
		
		EventControler.instance.setPane(siamPanel);
		EventControler.instance.setFrame(this);
		
		
		masterGame.init(siamPanel, j1 , j2);
		masterGame.setFrame(this);
	
		
		menuBar.add(menu);
		this.setJMenuBar(menuBar);
		
		menu.addMouseListener(mouseListener);
		
	}


}